<template>
  <el-dialog title="站点详情" :visible.sync="visible" width="60%" @close="closeDialog">
    <el-tabs v-model="activeTab" type="card">
      <el-tab-pane label="基本信息" name="basic-info">
        <el-descriptions title="站点基本信息" :column="2" border>
          <el-descriptions-item label="站点名称">{{ siteDetails.siteName }}</el-descriptions-item>
          <el-descriptions-item label="域名">{{ siteDetails.domain }}</el-descriptions-item>
          <el-descriptions-item label="协议">{{ siteDetails.protocol }}</el-descriptions-item>
          <el-descriptions-item label="端口">{{ siteDetails.port }}</el-descriptions-item>
          <el-descriptions-item label="状态">{{ siteDetails.status }}</el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="访问策略控制" name="access-control">
        <AccessControl :site-id="siteId" />
      </el-tab-pane>
      <el-tab-pane label="自定义规则" name="custom-rules">
        <CustomRules :site-id="siteId" />
      </el-tab-pane>
      <el-tab-pane label="访问频率控制" name="frequency-control">
        <FrequencyControl :site-id="siteId" />
      </el-tab-pane>
      <el-tab-pane label="BOT防护" name="bot-protection">
        <BotProtection :site-id="siteId" />
      </el-tab-pane>
      <el-tab-pane label="实时防护监控" name="real-time-monitoring">
        <RealTimeMonitoring :site-id="siteId" />
      </el-tab-pane>
      <el-tab-pane label="智学习" name="smart-learning">
        <SmartLearning :site-id="siteId" />
      </el-tab-pane>
      <el-tab-pane label="证书管理" name="certificate-management">
        <CertificateManagement :site-id="siteId" />
      </el-tab-pane>
    </el-tabs>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">关 闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import AccessControl from './components/AccessControl.vue';
import CustomRules from './components/CustomRules.vue';
import FrequencyControl from './components/FrequencyControl.vue';
import BotProtection from './components/BotProtection.vue';
import RealTimeMonitoring from './components/RealTimeMonitoring.vue';
import SmartLearning from './components/SmartLearning.vue';
import CertificateManagement from './components/CertificateManagement.vue';

export default {
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    siteDetails: {
      type: Object,
      required: true
    }
  },
  components: {
    AccessControl,
    CustomRules,
    FrequencyControl,
    BotProtection,
    RealTimeMonitoring,
    SmartLearning,
    CertificateManagement
  },
  data() {
    return {
      activeTab: 'basic-info',
      siteId: this.siteDetails.id
    };
  },
  watch: {
    siteDetails(newVal) {
      this.siteId = newVal.id; // 更新站点ID以支持动态变化
    }
  },
  methods: {
    closeDialog() {
      this.$emit('close');
    }
  }
};
</script>

<style scoped lang="scss">
.el-descriptions {
  margin-top: 20px;
}
</style>
